<script setup>
import { ref } from 'vue'
import {useUserInfoStore} from '@/stores/userInfo.js'
const userInfoStore = useUserInfoStore();
const userInfo = ref({
    //浅拷贝
        ...userInfoStore.info
})

import {userInfoUpdateService} from '@/api/user.js';
import {ElMessage} from 'element-plus';
const updateUserInfo = async ()=>{
    let result = await userInfoUpdateService(userInfo.value);
    if(result.code == 200){
        ElMessage.success('修改成功');
        userInfoStore.setInfo(userInfo.value);
    


    }else{
        ElMessage.error('修改失败');
    }
}


const rules = {
    nickname: [
        { required: true, message: '请输入用户昵称', trigger: 'blur' },
        {
            pattern: /^\S{2,10}$/,
            message: '昵称必须是2-10位的非空字符串',
            trigger: 'blur'
        }
    ],
    email: [
        { required: true, message: '请输入用户邮箱', trigger: 'blur' },
        { type: 'email', message: '邮箱格式不正确', trigger: 'blur' }
    ]
}
</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>基本资料</span>
            </div>
        </template>
        <el-row class="contentClass">
            <el-col :span="12">
                <el-form :model="userInfo" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="登录名称">
                        <!-- disabled 禁用-->
                        <el-input v-model="userInfo.username" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="用户昵称" prop="nickname">
                        <el-input v-model="userInfo.nickname"></el-input>
                    </el-form-item>
                    <el-form-item label="用户邮箱" prop="email">
                        <el-input v-model="userInfo.email"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click ="updateUserInfo">提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>
<style lang="scss" scoped>
.page-container {
    /* min-height: 100%; 设置元素的最小高度为父元素的高度，确保元素在内容较少时也能占据父元素的全部高度。
box-sizing: border-box; 设置元素的宽度和高度包括边框和内边距，使得元素的总宽度和高度不会超过指定的宽度和高度。
position: relative; 设置元素的相对定位，使得元素可以在其正常文档流中的位置上进行相对移动，不影响其他元素的位置。 */
    min-height: 100%;
    box-sizing: border-box;
    position: relative;
    background-color: rgb(242, 245, 248);

    .contentClass {

      display: flex;
      justify-content: center;
 
       
    }


}
</style>